package com.xc.freeapp.account.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.xc.freeapp.bean.AuthInfo;
import com.xc.freeapp.entity.Businessfloor;
import com.xc.freeapp.entity.Department;
import com.xc.freeapp.entity.Departments;
import com.xc.freeapp.entity.Hospital;
import com.xc.freeapp.exception.BaseException;
import com.xc.freeapp.service.HospitalService;
import com.xc.freeapp.util.AuthUtil;
import com.xc.freeapp.util.TokenAnnotation;
import com.xc.freeapp.util.UploadUtil;
/**
 * 医院相关模块controller
 * @author ZhouXinjie
 */
//@Controller
//@RequestMapping("v3/clinic")
//@Api(value="v3/clinic",description = "医院信息v3")
public class HospitalControllerV3 extends AbstractController{
	
	@Autowired
	private HospitalService hospitalService;
	
	/**
	 * 获取医院信息 医院简介
	 */
	@TokenAnnotation(required=false)
	@RequestMapping(value = "", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value = "获取医院信息 医院简介")
	public  Hospital getHospitalInfo() throws BaseException{
		AuthInfo authInfo = AuthUtil.getAuthInfo(getRequest());
		
        Hospital hospital = hospitalService.selectByPrimaryKey(authInfo.getAppIntId());
        hospital.setPics(UploadUtil.urlConversion(hospital.getPics()));
        hospital.setBriefpics(UploadUtil.urlConversion(hospital.getBriefpics()));
        hospital.setShowpics(UploadUtil.urlConversion(hospital.getShowpics()));
        hospital.setShowpics1(UploadUtil.urlConversion(hospital.getShowpics1()));
        hospital.setShowpics2(UploadUtil.urlConversion(hospital.getShowpics2()));
        hospital.setShowpics3(UploadUtil.urlConversion(hospital.getShowpics3()));
        hospital.setMappic(UploadUtil.urlConversion(hospital.getMappic()));
        if(hospital.getLat()==null||"".equals(hospital.getLat())){
        	hospital.setLat("31.236967");
        }
        if(hospital.getLng()==null||"".equals(hospital.getLng())){
        	hospital.setLng("121.467411");
        }
		return hospital;
	}
	/**
	 * 获取医院楼层信息
	 * */
	@TokenAnnotation(required=false)
	@RequestMapping(value = "/floorInfo",method =RequestMethod.GET )
	@ResponseBody
	@ApiOperation(value = "获取医院楼层信息")
	public  Map<String ,Object> getHospitalFloorInfo(@RequestParam(required=false,value="code") String code) throws BaseException{
		AuthInfo authInfo = AuthUtil.getAuthInfo(getRequest());
		 Map<String ,Object> responseMap =new HashMap<String, Object>();
        Map<String , Object> paramsmap = new HashMap<String, Object>();
        paramsmap.put("businessId", authInfo.getAppId());
        if(null!=code&&!"".equals(code)){
        	paramsmap.put("code", code);
        }
        List<Businessfloor> list = hospitalService.getFloorList(paramsmap);
        Hospital hospital = hospitalService.selectByPrimaryKey(authInfo.getAppIntId());
        hospital.setPics(UploadUtil.urlConversion(hospital.getPics()));
        hospital.setMappic(UploadUtil.urlConversion(hospital.getMappic()));
        responseMap.put("mappic",  hospital.getMappic());
        responseMap.put("Businessfloor",  list);
        
		return responseMap;
	}
	
}
